const { app, BrowserWindow } = require("electron");
const path = require("path");

// 需要安装件 cross-env
const NODE_ENV = process.env.NODE_ENV;

function createWindow() {
  const win = new BrowserWindow({
    width: 700,
    height: 700,
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false, // 设置为false，才能在渲染进程中使用electron api
    },
  });

  win.loadURL(
    NODE_ENV === "development"
      ? `http://localhost:8000`
      : `file://${path.join(__dirname, "../dist/index.html")}`
  );
  if (NODE_ENV === "development") {
    win.webContents.openDevTools();
  }
}

app.whenReady().then(() => {
  createWindow();
});

app.on("window-all-closed", () => {
  if (process.platform !== "darwin") {
    app.quit();
  }
});
